﻿using System.Collections.Generic;
using Microsoft.Practices.Prism.Modularity;
using Microsoft.Practices.Prism.Regions;
using Microsoft.Practices.ServiceLocation;
using Microsoft.Practices.Unity;
using TFS.Kanban.Commons.Commands;
using TFS.Kanban.Constants;
using TFS.Kanban.Modules.Dashboard.Commands;
using TFS.Kanban.Modules.Dashboard.Views;

namespace TFS.Kanban.Modules.Dashboard
{
    [Module(ModuleName = ModuleNames.Dashboard)]
    public class Module : IModule
    {
        public Module(IUnityContainer container, IRegionManager regionManager)
        {
            this.Container = container;
            this.RegionManager = regionManager;
        }

        #region Properties

        public IUnityContainer Container { get; private set; }
        public IRegionManager RegionManager { get; private set; }

        #endregion

        #region IModule Implementation

        public void Initialize()
        {
            RegisterViews();
            RegisterCommands();
        }

        #endregion

        #region Setup

        private void RegisterViews()
        {
            this.Container.RegisterType<DashboardView>(new ContainerControlledLifetimeManager());
            this.RegionManager.RegisterViewWithRegion(RegionNames.Main, () => ServiceLocator.Current.GetInstance<DashboardView>());
        }

        private void RegisterCommands()
        {
            var navigationCommands = ServiceLocator.Current.GetInstance<ICollection<CommandBase>>(CommandNames.NavigationCommands);
            navigationCommands.Add(ServiceLocator.Current.GetInstance<NavigateToDashboardCommand>());
        }

        #endregion
    }
}
